#!/usr/bin/python
# -*- coding: UTF-8 -*-

from business.User.UserCompetation import UserCompetation
import unittest

import re
import time
from datetime import datetime

import unittest

from business.login import Login
from pom.base import BaseDriver
from ddt import data, ddt, unpack, file_data
from selenium import webdriver
from common.api_corrent_answer import api_answer


@ddt
class TestUser(unittest.TestCase):

    @classmethod
    def setUpClass(cls):
        cls.dir = api_answer().api_answer("614be380aba34f2af8ebb8b2")

    def setUp(self):
        self.driver = webdriver.Chrome()
        BaseDriver(self.driver).get_url()
        self.l = Login(self.driver)
        self.u = UserCompetation(self.driver)

    def tearDown(self):
        BaseDriver(self.driver).quit_webdriver()

    # @file_data(r'D:\pythoncode\trainning\common\user.json')
    @data(
        ('广西55',"123456"),
        ('广西56', "123456"),
    )
    @unpack
    def test_answer(self, name, passwd):
        self.l.system_login(name, passwd)
        # score = api_answer().set_answer(self.dir, 44, name)
        # total_score = score[1]
        # score = score[0]
        # total_score = api_answer().set_answer(self.__class__.dir[0], 10, name)[1]
        # answer_file = self.dir + '/{}.csv'.format(name)
        answer_file = r'D:\pythoncode\trainning\common\anser_csv\614dcd3a87e74794ae3f2d76\j9.csv'
        # print(score, total_score)
        # print(round(int(score) / int(total_score), 4))
        # api_answer().set_answer(r'D:\pythoncode\trainning\common\anser_csv\测试大屏详细状态', 43, name)
        #
        # answer_file =  r'D:\pythoncode\trainning\common\anser_csv\1616'+ '\{}.csv'.format('j10')
        self.u.answer(answer_file, 73)
        time.sleep(5)


if __name__ == '__main__':
    unittest.main()
# import poplib
# import smtplib
# from email.mime.text import MIMEText
# import email
#
# _user = "3377548892@qq.com"
# _pwd = "gcthaljmquzzdafg"
# sent = smtplib.SMTP_SSL('smtp.qq.com', 465)  # 设置了SMTP服务器为stmp.qq.com 其端口号为465
# sent.login(_user, _pwd)  # 登陆
#
# to = ['honglian159753@vip.163.com']
# content = MIMEText('hhhhhhh,我是小仙女')  # MIMEText表示邮件发送具体内容
# content['Subject'] = 'hello'
# content['From'] = '3377548892@qq.com'
# content['To'] = ','.join(to)
# for i in range(100):
#     sent.sendmail('3377548892@qq.com', to, content.as_string())  # 三个参数
#     sent.close()  # 关闭邮箱


# import requests
#
#
#
# headers={
#     'Cookie':'DataAcquisition-sid=s%3ArWd5memXoVt5p3kDDF7ZvpHwJXBcrfPq.p0bNvvfH0BLAWDf6t4JFrgEK6Mbfm1e6NB3CfJTFscE; XSRF-TOKEN=GlTXKuOo-tLGapbdN0qonmaCQJQNEhhkOGj0',
#     'X-XSRF-TOKEN':'GlTXKuOo-tLGapbdN0qonmaCQJQNEhhkOGj0'
# }
#
# num = 0
# for i in range(0, 20):
#     num+=20
#     url = 'http://172.16.60.12/person/associateInfo?id=111202001514_xiaoli&offset={}&limit=20'.format(num)
#     response = requests.get(url, headers=headers).json()
#     print(url)
#     for j in range(0, 20):
#         print(response['data'][j]['personName'])

# """
# 竞赛用户答题
# """
# import csv
# import time
#
# from selenium import webdriver
# from datetime import datetime, date, timedelta
# from faker import Faker
# import random
#
# from selenium.common.exceptions import NoSuchElementException
# from selenium.webdriver import ActionChains
# from selenium.webdriver.common.by import By
# from selenium.webdriver.common.keys import Keys
#
# start = time.time()
#
# fake = Faker("zh_CN")
#
# option = webdriver.ChromeOptions()
# wd = webdriver.Chrome()
#
# wd.get("http://172.16.60.14")
# wd.maximize_window()
# wd.implicitly_wait(10)
#
# def com(username, passwd, file):
# #用户中心登录
# # 点击登录按钮
# #     wd.find_element_by_xpath("//../span[text() = '用户中心账号']").click()
# #
# #     # 输入邮箱
# #     wd.find_element_by_xpath("//input[@placeholder='邮箱/账号ID']").send_keys(username)
# #
# #     # 输入密码
# #     wd.find_element_by_xpath("//input[@placeholder = '密码']").send_keys(passwd)
# #
# #     wd.find_element_by_xpath("//span[text() = '授权并登录']").click()
#
#     # 系统用户登录
#     # 输入邮箱
#     wd.find_element_by_xpath("//input[@placeholder='请输入用户名']").send_keys(username)
#
#     # 输入密码
#     wd.find_element_by_xpath("//input[@placeholder = '请输入密码']").send_keys(passwd)
#
#     # 点击“授权并登录”按钮
#     wd.find_element_by_xpath("//span[text() = '登录']").click()
#
#     try:
#     # 存在参赛须知
#         wd.find_element(By.XPATH, '//div[@aria-label="参赛须知"]')
#         time.sleep(11)
#         # 勾选确认框
#         wd.find_element(By.XPATH, '//span[@class="el-checkbox__label"]').click()
#         wd.find_element(By.XPATH, '//span[text()="确认提交"]').click()
#
#     except NoSuchElementException:
#         print("没有参赛须知框")
#
#
#     # 统计题目模块总数
#     eles = wd.find_elements(By.XPATH, '//div[@class="f-toe-line-2 f-m-r-20"]')
#     print("题目总数: "+str(len(eles)))
#
#
#     # 点击第一题
#     eles[0].click()
#
#     x = 1
#     num = 0
#
#     # 题目类型
#     with open(file, 'r', encoding="gbk") as a:
#
#         csv_reader = csv.reader(a)
#         next(a)
#         for i in csv_reader:
#             if i == []:
#                 wd.find_element(By.XPATH, '//span[text()="下 一 题"]/..').click()
#                 num += 1
#                 continue
#             questionnum = wd.find_element(By.XPATH, '//div[@class="question-title el-col el-col-22"]/span').text
#             if (num + 1) % 10 == 0:
#                 time.sleep(10)
#             time.sleep(2)
#             # 题目类型
#             type = wd.find_element(By.XPATH, '//span[@class="f-fwb f-fc-link"]').text
#             if "填空" in type:
#                 wd.find_element(By.XPATH, '//textarea').send_keys(i[0])
#             elif "单选" in type:
#                 # print(wd.find_element(By.XPATH, '//div[@class = "el-radio-group"]//input[@value="'+i[0]+'"]/..').text)
#                 wd.find_element(By.XPATH, '//div[@class = "el-radio-group"]//input[@value="' + i[0] + '"]/..').click()
#                 # time.sleep(10)
#
#             elif "多选" in type:
#                 for x in i[0]:
#                     wd.find_element(By.XPATH, '//input[@value="' + x + '"]/..').click()
#             elif "主观" in type:
#                 wd.find_element(By.XPATH, '//textarea').send_keys(i[0])
#
#             ele = wd.find_element(By.XPATH, '//span[text()="提交答案"]/..')
#
#             # 跳过已经答过的题
#             if "disabled" in ele.get_attribute("class"):
#                 wd.find_element(By.XPATH, '//span[text()="下 一 题"]/..').click()
#             else:
#                 wd.find_element(By.XPATH, '//span[text()="提交答案"]').click()
#                 num += 1
#
#
#
#
#
#     wd.find_element(By.XPATH, '//span[text()="提交答案"]').click()
#     time.sleep(2)
#
#     x += 1
#     if x % 10 == 0:
#         time.sleep(10)
#
#     # 结束答题按钮
#     wd.find_element(By.XPATH, '//span[text()="结束答题"]/..').click()
#
#
#     # 提示的本次竞赛的名称
#     name = wd.find_element(By.XPATH, '//span[@class="f-fwb f-fc-333 f-m-r-10"]')
#
#
#
#     # 结束答题输入框
#     wd.find_element(By.XPATH, '//input[@placeholder="请输入本次竞赛名称"]').send_keys(name.text)
#
#     wd.find_element(By.XPATH, '//span[text()="确定"]').click()
#
#
#
#     time.sleep(10)
#
#     wd.quit()
